package com.example.module_park.ui

import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.lib_common.base.BaseFragment
import com.example.lib_common.base.state.Empty
import com.example.lib_common.base.state.Failed
import com.example.lib_common.base.state.Loading
import com.example.lib_common.base.state.Success
import com.example.lib_common.observeWithLifecycle
import com.example.module_park.R
import com.example.module_park.adapter.MultiLayoutAdapter
import com.example.module_park.databinding.FragmentParkBinding
import com.example.module_park.home.HomeViewModel
import com.example.module_park.model.MultiLayoutItem
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ParkFragment : BaseFragment<HomeViewModel,FragmentParkBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_park
    private val mViewModel: HomeViewModel by viewModels()



    override fun initView() {
        super.initView()
        mViewModel.getNotice(1,10)
        mViewModel.initList()
        mBinding.homeRv.layoutManager = LinearLayoutManager(requireContext())

    }

    override fun initData() {

    }

    override fun initListener() {
        mViewModel.noticeState.observeWithLifecycle(this){
            when(it){
                Empty -> {
                }
                is Failed -> {

                }
                Success -> {
                    val updatedItems = listOf(
                        MultiLayoutItem.Header("欢迎页面"),
                        MultiLayoutItem.Search("搜索商品..."),
                        MultiLayoutItem.Banner(R.mipmap.pack_banner),
                        MultiLayoutItem.HorizontalList(mViewModel.homeList),
                        MultiLayoutItem.SectionTitle("推荐商品"),
                        MultiLayoutItem.VerticalList(mViewModel.noticeList)
                    )
                    mBinding.homeRv.adapter = MultiLayoutAdapter(updatedItems)

                }

                Loading -> {}
            }
        }
    }

}